<template>
	<div>
		<div class="print" @click="generatorImage">
			<span>打印</span>
		</div>
		<div class="content" ref="addImage">
			<div ref="capture">需要保存的html页面</div>
		</div>
	</div>
</template>
<script>
import html2canvas from "html2canvas";
export default {
	methods: {
		//点击生成图片
		generatorImage() {
			html2canvas(this.$refs.capture).then((canvas) => {
				// this.$refs.addImage.append(canvas);//在下面添加canvas节点
				let link = document.createElement("a");
				link.href = canvas.toDataURL(); //下载链接
				link.setAttribute("download", "体检表.png");
				link.style.display = "none"; //a标签隐藏
				document.body.appendChild(link);
				link.click();
			});
		},
	},
};
</script>